#include "user_scope.h"

/************供FAE工程师使用*****************************/

#define UES_ADC_ISR
/*******************系统配置mcu and pwm set********************************/

#define MCU_MCLK_48MHZ      // MCU_MCLK_24MHZ  MCU_MCLK_48MHZ  mcu主频选择

#if defined(MCU_MCLK_48MHZ)
#define MCU_MCLK             (48000000LL)       /* MCU时钟频率 */
#elif defined(MCU_MCLK_24MHZ)
#define MCU_MCLK             (24000000LL)       /* MCU时钟频率 */
#endif
#define PWM_MCLK             ((u32)MCU_MCLK)    /* PWM时钟频率 */
#define PWM_PRSC             ((u8)0)            /* PWM预分频*/
#define PWM_FREQ             ((u16)16000)        /* PWM斩波频率 */
#define PWM_DEATIME_US       (0.5)              /* PWM死区时间us */
#define TIME0_PREIOD_VALUE   ((u32)(MCU_MCLK/2000 - 1))    /*timer0定时500us=2000hz装载值*/

/*******************系统任务时间配置********************************/
#define MIDDLE_FREQUENCY_TASK_MS   2   //中频任务周期:ms
#define LOW_FREQUENCY_TASK_MS      (2)//低频任务周期

/*******************电流采样adc set********************************/
#define ADC_VDD_VEF          (2.5)   //Unit:v
#define ADC_RS_SAMPLE        (0.05)  //Unit:ohm

#if defined(DPM_PIN16_DOUBLE_RS)

#define PGA_GAIN_SET         (PGA_AMP_GAIN9) // 实际的增益
#define ADC_IN_REXT          (68.0)  //Unit;ohm adc采样输入串1k电阻
#define ADC_PGA_GAIN         ((float)((1<<PGA_GAIN_SET) + 1)*20000.0/(21200.0 + ADC_IN_REXT))    //Unit:none
#define HAREWARE_IMAX        (((float)ADC_VDD_VEF/(ADC_RS_SAMPLE*ADC_PGA_GAIN))) //Unit:A

#elif defined(DPM_PIN16_SINGLE_RS)

#define PGA_GAIN_SET         (PGA_AMP_GAIN9) // 实际的增益
#define ADC_IN_REXT          (1000.0)  //Unit;ohm adc采样输入串1k电阻
//#define PGA_GAIN_SET         (PGA_AMP_GAIN17) // 实际的增益
//#define ADC_IN_REXT          (20000.0)  //Unit;ohm adc采样输入串1k电阻
#define ADC_PGA_GAIN         ((float)((1<<PGA_GAIN_SET) + 1)*20000.0/(21200.0 + ADC_IN_REXT))    //Unit:none
#define HAREWARE_IMAX        (((float)ADC_VDD_VEF/(ADC_RS_SAMPLE*ADC_PGA_GAIN))) //Unit:A
	
#endif
/***************电压采样配置************************************/
#if(HARDWARE_UDC_SAMPLE_ENABLE == 1)
#define UDC_SAMPLE_R1   (22000.0)
#define UDC_SAMPLE_R2   (2400.0)
#define HAREWARE_UDCMAX ((float) 5.0*(UDC_SAMPLE_R1 + UDC_SAMPLE_R2)/UDC_SAMPLE_R2) //338.33V
#else
#define HAREWARE_UDCMAX (VOLT_UDC)
#endif

/*******************其他电机参数设置，预留********************************/
#define MOTOR_PM_FLUX        (1.0)  //Unit:Wb
#define MOTOR_INERTIA        (1.0)  //Unit:Kg.m^2

/***************电流采样拓扑相关配置************************************************/
#if CURRENT_SAMPLE_TOPOLOGY == 0
    #define ONE_SHUNT_TOPOLOGY
    #define SAMPLE_WINDOW     (1.2)//(2.0)      //采样窗口时间：单位us
    #define SAMPLE_01_OFFSET  (0.4768)          ////采样点1偏移：单位us
    #define SAMPLE_02_OFFSET  (SAMPLE_01_OFFSET)////采样点2偏移：单位us
#elif CURRENT_SAMPLE_TOPOLOGY == 1
    #define TWO_SHUNT_TOPOLOGY
#endif

// 位置检测方式
#define DEFAULT_VELOCITY_SENSOR 0
#if DEFAULT_VELOCITY_SENSOR == 0
		#define VS_SMO
#elif DEFAULT_VELOCITY_SENSOR == 1
    #define VS_FO
#endif

// 启动策略
#define START_TRATEGY 3 
#if START_TRATEGY == 0
#elif START_TRATEGY == 1
    #define ROTOR_INITIAL_POSITION_DETECT
#elif START_TRATEGY == 2
    #define ROTOR_INITIAL_POSITION_DETECT
#elif START_TRATEGY == 3
    #define ROTOR_INITIAL_POSITION_DETECT
    #define ON_THE_FLY_STATE                
#endif                         
/*******************系统切换相关配置********************************/

#define OBSERVER_GAIN_SWITCH_TIME (50.0)      //系统增益切换滤波时间ms，用于堵转限制功率
#define REVERSE_BRAKE_TIME        (2600.0)    //反转刹车时间 ms ：大扇叶刹车时间长，小扇叶刹车时间短

///*******************end set********************************/